package com.nit.lab.mapper.ship;


import com.nit.lab.dto.ship.WorkDTO;
import com.nit.lab.dto.ship.WorkTypeDTO;
import com.nit.lab.entity.ship.ShipEntity;
import com.nit.lab.entity.ship.WorkEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface WorkMapper {

    /**
     * @Description: 获取作业内容
     * @Author: sober
     * @Date: 2021/2/2
     */

    @Select({"<script>SELECT * " +
            "FROM work , work_detail,ship " +
            "WHERE work.work_type=work_detail.work_type AND work.ship_id=ship.ship_id " +
            "<if test='shipId != null'>AND ship_id = #{shipId}  </if>" +
            "</script>"})
    List<WorkDTO> query(@Param("shipId") Integer shipId) throws Exception;



    /**
     * @Description: 获取作业列表
     * @Author: sober
     * @Date: 2021/2/2
     */

    @Select({"<script>SELECT * " +
            "FROM work_detail " +
            "WHERE 1 = 1 " +
            "</script>"})
    List<WorkTypeDTO> queryWorkType() throws Exception;


    @Select({"<script>SELECT COUNT(*) " +
            "FROM work " +
            "WHERE 1 = 1 " +
            "</script>"})
    Long count4Table() throws Exception;

    @Insert({"INSERT INTO work( " +
            "ship_id, company_name, people_number, phone, in_time, out_time, " +
            "up_time, down_time, start_time, end_time, work_time,  work_type, work_detail,board_ship, note ,gmt_create) " +
            "VALUES( #{entity.shipId}, #{entity.companyName}, #{entity.peopleNumber}, " +
            "#{entity.phone}, #{entity.inTime}, #{entity.outTime}, " +
            "#{entity.upTime}, #{entity.downTime}, #{entity.startTime}, #{entity.endTime}, " +
            "#{entity.workTime}, #{entity.workType}, #{entity.workDetail}, #{entity.boardShip}, #{entity.note}, #{entity.gmtCreate})"})
    @Options(useGeneratedKeys = true, keyProperty = "workId", keyColumn = "work_id")
    Integer add(@Param("entity") WorkEntity workEntity) throws Exception;

    @Update({"UPDATE work " +
            "SET in_time = #{entity.inTime}, " +
            "out_time = #{entity.outTime}, " +
            "start_time = #{entity.startTime}, " +
            "end_time = #{entity.endTime}, " +
            "work_time = #{entity.workTime}, " +
            "note = #{entity.note} " +
            "WHERE work_id = #{entity.workId}"})
    Integer update(@Param("entity") WorkEntity workEntity) throws Exception;


    @Delete("Delete from work WHERE work_id = #{workId}")
    Integer remove(@Param("workId") Long workId) throws Exception;
}
